2020-2021 Sunseeker Telemetry and Lighting System
usci_a_uart_ex4_idlelineMultiprocessorTX.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
60 //******************************************************************************
61 #define BAUD_RATE 9600
62 #define TRANSMIT_DATA_COUNT 0x02
63 #define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS 0xAA
64 
65 uint8_t receivedData = 0x00, transmitData = 0x00;
68 
69 void main (void)
70 {
71  //Stop WDT
72  WDT_A_hold(WDT_A_BASE);
73 
74  //P3.4,5 = USCI_A0 TXD/RXD
75  GPIO_setAsPeripheralModuleFunctionInputPin(
76  GPIO_PORT_P3,
77  GPIO_PIN4 + GPIO_PIN5
78  );
79 
80  //Initialize USCI UART module
81  //Baudrate = 9600, clock freq = 1.048MHz
82  //UCBRx = 6, UCBRFx = 13, UCBRSx = 0, UCOS16 = 1
83  USCI_A_UART_initParam param = {0};
84  param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
85  param.clockPrescalar = 6;
86  param.firstModReg = 13;
87  param.secondModReg = 0;
88  param.parity = USCI_A_UART_NO_PARITY;
89  param.msborLsbFirst = USCI_A_UART_MSB_FIRST;
90  param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
91  param.uartMode = USCI_A_UART_IDLE_LINE_MULTI_PROCESSOR_MODE;
92  param.overSampling = USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
93  if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
94  return;
95  }
96 
97  //Enable UART module for operation
98  USCI_A_UART_enable(USCI_A0_BASE);
99 
100  //Send Address Frame
101  USCI_A_UART_transmitAddress(USCI_A0_BASE,
103 
104  //Enable Receive Interrupt
105  USCI_A_UART_clearInterrupt(USCI_A0_BASE,
106  USCI_A_UART_RECEIVE_INTERRUPT);
107  USCI_A_UART_enableInterrupt(USCI_A0_BASE,
108  USCI_A_UART_RECEIVE_INTERRUPT);
109 
110  //Enter LPM3, interrupts enabled
111  __bis_SR_register(LPM3_bits + GIE);
112  __no_operation();
113 }
114 
115 //******************************************************************************
116 //
117 //This is the USCI_A0 interrupt vector service routine.
118 //
119 //******************************************************************************
120 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
121 #pragma vector=USCI_A0_VECTOR
122 __interrupt
123 #elif defined(__GNUC__)
124 __attribute__((interrupt(USCI_A0_VECTOR)))
125 #endif
126 void USCI_A0_ISR (void)
127 {
128  switch (__even_in_range(UCA0IV,4)){
129  //Vector 2 - RXIFG
130  case 2:
131 
132  //USCI_A0 TX buffer ready?
133  while (!USCI_A_UART_getInterruptStatus(USCI_A0_BASE,
134  USCI_A_UART_TRANSMIT_INTERRUPT)) ;
135 
136  //Receive the data
137  receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
138 
139  if (transmitDataCount){
140  //Send data
141  USCI_A_UART_transmitData(USCI_A0_BASE,
142  transmitData++);
144  } else {
145  //Send Address
146  USCI_A_UART_transmitAddress(USCI_A0_BASE,
149  }
150 
151  break;
152  default: break;
153  }
154 }
155 
MPU_initThreeSegmentsParam param
__no_operation()
#define STATUS_FAIL
Definition: hw_memmap.h:23
#define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS